﻿using FixMath;
using UnityEngine;

namespace UniFramework.Actor
{
	/// <summary>
	/// 逻辑对象，负责帧同步中逻辑对象
	/// </summary>
	public abstract class LogicObject : MonoBehaviour
	{
		public long id = -1; //供外部使用的唯一id
		private FixIntVector3 logicPos; //逻辑对象逻辑位置
		private FixIntVector3 logicAngle; //逻辑对象旋转速度
		public bool isActive; //当前逻辑对象是否激活
		public bool isDestroy;
		public RenderObject RenderObject { get; protected set; } //渲染对象

		public virtual void OnCreate()
		{
			isActive = true;
			isDestroy = false;
		}

		public virtual void OnLogicFrameUpdate(int curFrame)
		{
		}

		public virtual void OnDie()
		{
			isActive = false;
			isDestroy = true;
			GameObject.Destroy(gameObject);
		}

		public void SetId(long externalId) => this.id = externalId;


		public FixIntVector3 LogicPos
		{
			get => new FixIntVector3(transform.position);
			// get => logicPos;
			// set { logicPos = value; }
			set
			{
				logicPos = value;
				transform.position = value.ToVector3();
			}
		}

		public FixIntVector3 LogicAngle
		{
			get => logicAngle;
			set => logicAngle = value;
		}
	}
}